package com.shop.shoporder.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.shop.shoporder.common.HttpRequest;
import com.shop.shoporder.entity.HttpRequestConfig;
import com.shop.shoporder.service.FinaceService;
import net.sf.json.JSONArray;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("finaceService")
public class FinaceServiceImpl implements FinaceService {

    @Override
    public JSONObject getBalanceAllJ(Integer userNoId1) {
        if (userNoId1 > 0) {
            String url = HttpRequestConfig.finaceServerUrl+"/wap/getBalanceAllJ";
            String userNoId = "userNoId=" + userNoId1;
            String result = HttpRequest.sendGet(url, userNoId);

            System.out.println(result);

            JSONObject str = JSONObject.parseObject(result);
            String code = str.get("code").toString();
            if ("000000".equals(code)) {
                JSONObject strData = JSONObject.parseObject(str.get("data").toString());
                return strData;
            } else {
                return null;
            }
        }else {
            return null;
        }
    }

    @Override
    public JSONObject getBalanceAllX(Integer userNoId1) {
        if (userNoId1 > 0) {
            String url = HttpRequestConfig.finaceServerUrl+"/wap/getBalanceAllX";
            String userNoId = "userNoId=" + userNoId1;
            String result = HttpRequest.sendGet(url, userNoId);
            JSONObject str = JSONObject.parseObject(result);
            String code = str.get("code").toString();
            if ("000000".equals(code)) {
                JSONObject strData = JSONObject.parseObject(str.get("data").toString());
                return strData;
            } else {
                return null;
            }
        }else {
            return null;
        }
    }

    @Override
    public JSONArray getWeChatList(Integer userNoId1, String remark) {
        if (userNoId1 > 0) {
            String url = HttpRequestConfig.finaceServerUrl+"/wap/getWeChatList";
            String userNoId = "userNoId=" + userNoId1+"&remark="+remark;
            String result = HttpRequest.sendGet(url, userNoId);
            JSONObject str = JSONObject.parseObject(result);
            String code = str.get("code").toString();
            if ("000000".equals(code)) {
                System.out.println(str.toJSONString());
                JSONArray jsonArray=JSONArray.fromObject(str.get("data").toString());
//                JSONObject strData = JSONObject.parseObject(str.get("data").toString());
                return jsonArray;
            } else {
                return null;
            }
        }else {
            return null;
        }
    }

}
